home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / PRISYM.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  13KB  |  681 lines

  1. /*    SCCS Id: @(#)prisym.c    3.0    89/11/15
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. #ifdef WORM
  8. #include "wseg.h"
  9. #include "lev.h"
  10.  
  11. STATIC_DCL void FDECL(pwseg, (struct wseg *));
  12. #endif
  13.  
  14. #ifdef OVL0
  15.  
  16. void
  17. atl(x,y,ch)
  18. register int x, y;
  19. char ch;
  20. {
  21.     register struct rm *crm = &levl[x][y];
  22.  
  23.     if(x<0 || x>COLNO-1 || y<0 || y>ROWNO-1){
  24.         impossible("atl(%d,%d,%c)",x,y,ch);
  25.         return;
  26.     }
  27.     if(crm->seen && crm->scrsym == ch) return;
  28.     /* crm->scrsym = (uchar) ch; */
  29.     /* wrong if characters are signed but uchar is larger than char,
  30.      * and ch, when passed, was greater than 127.
  31.      * We probably should _really_ go around changing atl to take a
  32.      * uchar for its third argument...
  33.      */
  34.     crm->scrsym = (uchar)((unsigned char) ch);
  35.     crm->new = 1;
  36.     on_scr(x,y);
  37. }
  38.  
  39. void
  40. on_scr(x,y)
  41. register int x, y;
  42. {
  43.     if(x < scrlx) scrlx = x;
  44.     if(x > scrhx) scrhx = x;
  45.     if(y < scrly) scrly = y;
  46.     if(y > scrhy) scrhy = y;
  47. }
  48.  
  49. #endif /* OVL0 */
  50. #ifdef OVL2
  51.  
  52. /* call: (x,y) - display
  53.     (-1,0) - close (leave last symbol)
  54.     (-1,-1)- close (undo last symbol)
  55.     (-1,let)-open: initialize symbol
  56.     (-2,let)-change let
  57.     (-3,let)-set color
  58. */
  59.  
  60. void
  61. tmp_at(x, y)
  62. int x, y;
  63. {
  64. #ifdef LINT    /* static schar prevx, prevy; static char let; */
  65. schar prevx=0, prevy=0;
  66. uchar let;
  67. uchar col;
  68. #else
  69. static schar NEARDATA prevx, NEARDATA prevy;
  70. static uchar NEARDATA let;
  71. static uchar NEARDATA col;
  72. #endif
  73.  
  74.     switch ((int)x) {
  75.         case -2:        /* change let call */
  76.         let = y;
  77.         return;
  78.         case -1:        /* open or close call */
  79.         if ((int)y >= 0) {
  80.             let = y;
  81.             prevx = -1;
  82.             col = AT_ZAP;
  83.             return;
  84.         }
  85.         break;
  86.         case -3:        /* set color call */
  87.         col = y;
  88.         return;
  89.     }
  90.     if(prevx >= 0 && cansee(prevx,prevy)) {
  91.         delay_output();
  92.         prl(prevx, prevy);    /* in case there was a monster */
  93.         at(prevx, prevy, levl[prevx][prevy].scrsym, AT_APP);
  94.     }
  95.     if(x >= 0){    /* normal call */
  96.         if(cansee(x,y)) at(x,y,let,col);
  97.         prevx = x;
  98.         prevy = y;
  99.     } else {    /* close call */
  100.         let = 0;
  101.         prevx = -1;
  102.     }
  103. }
  104.  
  105. /* like the previous, but the symbols are first erased on completion */
  106. void
  107. Tmp_at2(x, y)
  108. int x, y;
  109. {
  110. #ifdef LINT    /* static char let; static xchar cnt; static coord tc[COLNO]; */
  111. uchar let;
  112. xchar cnt;
  113. coord tc[COLNO];    /* but watch reflecting beams! */
  114. # ifdef TEXTCOLOR
  115. uchar col;
  116. # endif
  117. #else
  118. static uchar NEARDATA let;
  119. static xchar NEARDATA cnt;
  120. static coord NEARDATA tc[COLNO];    /* but watch reflecting beams! */
  121. # ifdef TEXTCOLOR
  122. static uchar NEARDATA col;
  123. # endif
  124. #endif
  125. register int xx,yy;
  126.     switch((int)x) {
  127.         case -1:
  128.         if(y > 0) {    /* open call */
  129.             let = y;
  130.             cnt = 0;
  131. #ifdef TEXTCOLOR
  132.             col = AT_ZAP;
  133. #endif
  134.             return;
  135.         }
  136.         /* close call (do not distinguish y==0 and y==-1) */
  137.         while(cnt--) {
  138.             xx = tc[cnt].x;
  139.             yy = tc[cnt].y;
  140.             prl(xx, yy);
  141.             at(xx, yy, levl[xx][yy].scrsym, AT_APP);
  142.         }
  143.         cnt = let = 0;    /* superfluous */
  144.         return;
  145.         case -2:        /* change let call */
  146.         let = y;
  147.         return;
  148. #ifdef TEXTCOLOR
  149.         case -3:        /* set color call */
  150.         col = y;
  151.         return;
  152. #endif
  153.     }
  154.     /* normal call */
  155.     if(cansee(x,y)) {
  156.         if(cnt) delay_output();
  157. #ifdef TEXTCOLOR
  158.         at(x,y,let,col);
  159. #else
  160.         at(x,y,let,AT_ZAP);
  161. #endif
  162.         tc[cnt].x = x;
  163.         tc[cnt].y = y;
  164.         if(++cnt >= COLNO) panic("Tmp_at2 overflow?");
  165.         levl[x][y].new = 0;    /* prevent pline-nscr erasing --- */
  166.     }
  167. }
  168.  
  169. #endif /* OVL2 */
  170. #ifdef OVL1
  171.  
  172. void
  173. curs_on_u()
  174. {
  175. #ifdef CLIPPING
  176.     cliparound(u.ux, u.uy);
  177.     (void)win_curs(u.ux, u.uy);
  178. #else
  179.     curs(u.ux, u.uy+2);
  180. #endif
  181. }
  182.  
  183. void
  184. pru()
  185. {
  186.     if(u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy))
  187.         /* if(! levl[u.udisx][u.udisy].new) */
  188.             if(!vism_at(u.udisx, u.udisy))
  189.                 newsym(u.udisx, u.udisy);
  190.     if(Invisible
  191. #ifdef POLYSELF
  192.             || u.uundetected
  193. #endif
  194.                     ) {
  195.         u.udispl = 0;
  196.         prl(u.ux,u.uy);
  197.     } else
  198.     if(!u.udispl || u.udisx != u.ux || u.udisy != u.uy) {
  199.         atl(u.ux, u.uy, (char) u.usym);
  200.         u.udispl = 1;
  201.         u.udisx = u.ux;
  202.         u.udisy = u.uy;
  203.     }
  204.     levl[u.ux][u.uy].seen = 1;
  205. }
  206.  
  207. #endif /* OVL1 */
  208. #ifdef OVL0
  209.  
  210. /* print a position that is visible for @ */
  211. void
  212. prl(x,y)
  213. int x, y;
  214. {
  215.     register struct rm *room;
  216.     register struct monst *mtmp = (struct monst *)0;
  217.     register struct obj *otmp;
  218.     register struct trap *ttmp;
  219.  
  220.     if(x == u.ux && y == u.uy && !Invisible
  221. #ifdef POLYSELF
  222.                         && !u.uundetected
  223. #endif
  224.                                 ) {
  225.         pru();
  226.         return;
  227.     }
  228.     if(!isok(x,y)) return;
  229.     room = &levl[x][y];
  230.     if((!room->typ) ||
  231.        (IS_ROCK(room->typ) && levl[u.ux][u.uy].typ == CORR &&
  232.                   !levl[u.ux][u.uy].lit))
  233.         /* the only lit corridor squares should be the entrances to
  234.          * outside castle areas */
  235.         return;
  236.     if(MON_AT(x, y)) mtmp = m_at(x,y);
  237.     if(mtmp && !mtmp->mhide &&
  238.         (!mtmp->minvis || See_invisible)) {
  239. #ifdef WORM
  240.         if(m_atseg)
  241.             pwseg(m_atseg);
  242.         else
  243. #endif
  244.         pmon(mtmp);
  245.     }
  246.     else if(OBJ_AT(x, y) && !is_pool(x,y)) {
  247.         otmp = level.objects[x][y];
  248.         atl(x,y,Hallucination ? rndobjsym() : otmp->olet);
  249.     }
  250.     else if(room->gmask && !is_pool(x,y))
  251.         atl(x,y,Hallucination ? rndobjsym() : GOLD_SYM);
  252.     else if((!mtmp || mtmp->data == &mons[PM_GIANT_SPIDER]) &&
  253.           (ttmp = t_at(x,y)) && ttmp->ttyp == WEB)
  254.         atl(x,y,(char)WEB_SYM);
  255.     else if(mtmp && (!mtmp->minvis || See_invisible)) {
  256.         /* must be a hiding monster, but not hiding right now */
  257.         /* assume for the moment that long worms do not hide */
  258.         pmon(mtmp);
  259.     }
  260.     else if(!room->seen || room->scrsym == STONE_SYM) {
  261.         room->new = room->seen = 1;
  262.         newsym(x,y);
  263.         on_scr(x,y);
  264.     }
  265.     room->seen = 1;
  266. }
  267.  
  268. uchar
  269. news0(x,y)
  270. register xchar x,y;
  271. {
  272.     register struct obj *otmp;
  273.     register struct trap *ttmp;
  274.     struct rm *room;
  275.     register uchar tmp;    /* don't compare char with uchar -- OIS */
  276.     register int croom;
  277.  
  278.     room = &levl[x][y];
  279.     /* note: a zero scrsym means to ignore the presence of objects */
  280.     if(!room->seen) tmp = STONE_SYM;
  281.     else if(room->typ == POOL || room->typ == MOAT) tmp = POOL_SYM;
  282.     else if(OBJ_AT(x, y) && !Blind && room->scrsym) {
  283.         otmp = level.objects[x][y];
  284.         tmp = Hallucination ? rndobjsym() : otmp->olet;
  285.     }
  286.     else if(room->gmask && !Blind && room->scrsym) 
  287.         tmp = Hallucination ? rndobjsym() : GOLD_SYM;
  288.     else if(x == xupstair && y == yupstair) tmp = UP_SYM;
  289.     else if(x == xdnstair && y == ydnstair) tmp = DN_SYM;
  290. #ifdef STRONGHOLD
  291.     else if(x == xupladder && y == yupladder) tmp = UPLADDER_SYM;
  292.     else if(x == xdnladder && y == ydnladder) tmp = DNLADDER_SYM;
  293. #endif
  294.     else if((ttmp = t_at(x,y)) && ttmp->ttyp == WEB) tmp = WEB_SYM;
  295.     else if(ttmp && ttmp->tseen) tmp = TRAP_SYM;
  296.     else switch(room->typ) {
  297.     case SCORR:
  298.         tmp = ' ';    /* _not_ STONE_SYM! */
  299.         break;
  300.     case SDOOR:
  301.         croom = inroom(x,y);
  302.         if(croom == -1) {
  303. #ifdef STRONGHOLD
  304.             if(IS_WALL(levl[x-1][y].typ)) tmp = HWALL_SYM;
  305.             else tmp = VWALL_SYM;
  306.             break;
  307. #else
  308.             impossible("door %d %d not in room",x,y);
  309. #endif
  310.         }
  311.         if(rooms[croom].lx-1 == x || rooms[croom].hx+1 == x)
  312.             tmp = VWALL_SYM;
  313.         else    /* SDOORs aren't created on corners */
  314.             tmp = HWALL_SYM;
  315.           break;
  316.     case HWALL:
  317. #ifdef STRONGHOLD
  318.         if (is_maze_lev && is_drawbridge_wall(x,y) >= 0) tmp = DB_HWALL_SYM;
  319.         else
  320. #endif
  321.         tmp = HWALL_SYM;
  322.         break;
  323.     case VWALL:
  324. #ifdef STRONGHOLD
  325.         if (is_maze_lev && is_drawbridge_wall(x,y) >= 0) tmp = DB_VWALL_SYM;
  326.         else
  327. #endif
  328.         tmp = VWALL_SYM;
  329.         break;
  330.     case TLCORNER:
  331.         tmp = TLCORN_SYM;
  332.         break;
  333.     case TRCORNER:
  334.         tmp = TRCORN_SYM;
  335.         break;
  336.     case BLCORNER:
  337.         tmp = BLCORN_SYM;
  338.         break;
  339.     case BRCORNER:
  340.         tmp = BRCORN_SYM;
  341.         break;
  342.     case DOOR:
  343.         if (room->doormask == D_NODOOR || room->doormask & D_BROKEN)
  344.             tmp = NO_DOOR_SYM;
  345.         else if (room->doormask & (D_CLOSED|D_LOCKED))
  346.             tmp = CLOSED_DOOR_SYM;
  347.         /* We know door is open. */
  348.         else {
  349.             croom=inroom(x,y);
  350.             if(croom == -1) {
  351. #ifdef STRONGHOLD
  352.             if(IS_WALL(levl[x-1][y].typ)||IS_WALL(levl[x+1][y].typ))
  353.                 tmp = H_OPEN_DOOR_SYM;
  354.             else
  355.                 tmp = V_OPEN_DOOR_SYM;
  356. #else
  357.             impossible("door %d %d not in room",x,y);
  358. #endif
  359.             } else if(rooms[croom].ly<=y && y<=rooms[croom].hy)
  360.             tmp = V_OPEN_DOOR_SYM;
  361.             else
  362.             tmp = H_OPEN_DOOR_SYM;
  363.         }
  364.         break;
  365.     case CORR:
  366.         tmp = CORR_SYM;
  367.         break;
  368. #ifdef STRONGHOLD
  369.     case DRAWBRIDGE_UP:
  370.         if((room->drawbridgemask & DB_UNDER) == DB_MOAT) tmp = POOL_SYM;
  371.         else tmp = ROOM_SYM;
  372.         break;
  373.     case DRAWBRIDGE_DOWN:
  374. #endif /* STRONGHOLD /**/
  375.     case ROOM:
  376.         if(room->lit || cansee(x,y) || Blind) tmp = ROOM_SYM;
  377.         else tmp = STONE_SYM;
  378.         break;
  379. #ifdef POLYSELF
  380.     case STONE:
  381.         tmp = STONE_SYM;
  382.         break;
  383. #endif
  384. #ifdef FOUNTAINS
  385.     case FOUNTAIN:
  386.         tmp = FOUNTAIN_SYM;
  387.         break;
  388. #endif
  389. #ifdef THRONES
  390.     case THRONE:
  391.         tmp = THRONE_SYM;
  392.         break;
  393. #endif
  394. #ifdef SINKS
  395.     case SINK:
  396.         tmp = SINK_SYM;
  397.         break;
  398. #endif
  399. #ifdef ALTARS
  400.     case ALTAR:
  401.         tmp = ALTAR_SYM;
  402.         break;
  403. #endif
  404.     case CROSSWALL:
  405.         tmp = CRWALL_SYM;
  406.         break;
  407.     case TUWALL:
  408.         tmp = TUWALL_SYM;
  409.         break;
  410.     case TDWALL:
  411.         tmp = TDWALL_SYM;
  412.         break;
  413.     case TLWALL:
  414.         tmp = TLWALL_SYM;
  415.         break;
  416.     case TRWALL:
  417.         tmp = TRWALL_SYM;
  418.         break;
  419. /*
  420.     case POOL:
  421.         tmp = POOL_SYM;
  422.         break;
  423. */
  424.     default:
  425.         tmp = ERRCHAR;
  426.     }
  427.     return(tmp);
  428. }
  429.  
  430. void
  431. newsym(x,y)
  432. register int x, y;
  433. {
  434.     atl(x,y,(char)news0(x,y));
  435. }
  436.  
  437. #endif /* OVL0 */
  438. #ifdef OVLB
  439.  
  440. /* used with wand of digging (or pick-axe): fill scrsym and force display */
  441. /* also when a POOL evaporates */
  442. void
  443. mnewsym(x, y)
  444. register int x, y;
  445. {
  446.     register struct rm *room;
  447.     uchar newscrsym;    /* OIS */
  448.  
  449.     if(!vism_at(x,y)) {
  450.         room = &levl[x][y];
  451.         newscrsym = news0(x,y);
  452.         if(room->scrsym != newscrsym) {
  453.             room->scrsym = newscrsym;
  454.             room->seen = 0;
  455.         }
  456.     }
  457. }
  458.  
  459. #endif /* OVLB */
  460. #ifdef OVL1
  461.  
  462. void
  463. nosee(x,y)
  464. register int x, y;
  465. {
  466.     register struct rm *room;
  467.  
  468.     if(!isok(x,y)) return;
  469.     room = &levl[x][y];
  470.     if(levl[x][y].scrsym == ROOM_SYM
  471.        && !room->lit && !Blind) {
  472.         room->scrsym = STONE_SYM;    /* was ' ' -- OIS */
  473.         room->new = 1;
  474.         on_scr(x,y);
  475.     }
  476. }
  477.  
  478. void
  479. prl1(x,y)
  480. register int x, y;
  481. {
  482.     if(u.dx) {
  483.         if(u.dy) {
  484.             prl(x-(2*u.dx),y);
  485.             prl(x-u.dx,y);
  486.             prl(x,y);
  487.             prl(x,y-u.dy);
  488.             prl(x,y-(2*u.dy));
  489.         } else {
  490.             prl(x,y-1);
  491.             prl(x,y);
  492.             prl(x,y+1);
  493.         }
  494.     } else {
  495.         prl(x-1,y);
  496.         prl(x,y);
  497.         prl(x+1,y);
  498.     }
  499. }
  500.  
  501. void
  502. nose1(x,y)
  503. register int x, y;
  504. {
  505.     if(u.dx) {
  506.         if(u.dy) {
  507.             nosee(x,u.uy);
  508.             nosee(x,u.uy-u.dy);
  509.             nosee(x,y);
  510.             nosee(u.ux-u.dx,y);
  511.             nosee(u.ux,y);
  512.         } else {
  513.             nosee(x,y-1);
  514.             nosee(x,y);
  515.             nosee(x,y+1);
  516.         }
  517.     } else {
  518.         nosee(x-1,y);
  519.         nosee(x,y);
  520.         nosee(x+1,y);
  521.     }
  522. }
  523.  
  524. int
  525. vism_at(x,y)
  526. register int x, y;
  527. {
  528.     if(x == u.ux && y == u.uy && !Invisible) return(1);
  529.  
  530.     if(MON_AT(x, y))
  531.         return(showmon(m_at(x,y)));
  532.     return(0);
  533. }
  534.  
  535. #endif /* OVL1 */
  536. #ifdef OVLB
  537.  
  538. #ifdef NEWSCR
  539. void
  540. pobj(obj)
  541. register struct obj *obj;
  542. {
  543.     register int show = (!obj->oinvis || See_invisible) &&
  544.         cansee(obj->ox,obj->oy);
  545.     if(obj->odispl){
  546.         if(obj->odx != obj->ox || obj->ody != obj->oy || !show)
  547.         if(!vism_at(obj->odx,obj->ody)){
  548.             newsym(obj->odx, obj->ody);
  549.             obj->odispl = 0;
  550.         }
  551.     }
  552.     if(show && !vism_at(obj->ox,obj->oy)){
  553.         atl(obj->ox,obj->oy,obj->olet);
  554.         obj->odispl = 1;
  555.         obj->odx = obj->ox;
  556.         obj->ody = obj->oy;
  557.     }
  558. }
  559. #endif /* NEWSCR /**/
  560.  
  561. void
  562. unpobj(obj)
  563. register struct obj *obj;
  564. {
  565. /*     if(obj->odispl){
  566.         if(!vism_at(obj->odx, obj->ody))
  567.             newsym(obj->odx, obj->ody);
  568.         obj->odispl = 0;
  569.     }
  570. */
  571.     if(!vism_at(obj->ox,obj->oy))
  572.         newsym(obj->ox,obj->oy);
  573. }
  574.  
  575. #ifdef WORM
  576. STATIC_OVL void
  577. pwseg(wtmp)
  578. register struct wseg *wtmp;
  579. {
  580.     if(!wtmp->wdispl){
  581.         atl(wtmp->wx, wtmp->wy, S_WORM_TAIL);
  582.         wtmp->wdispl = 1;
  583.     }
  584. }
  585. #endif
  586.  
  587.  
  588. #ifdef STUPID_CPP    /* otherwise these functions are macros in rm.h */
  589. boolean IS_WALL(typ)
  590. unsigned typ;
  591. {
  592.     return(typ && typ <= TRWALL);
  593. }
  594.  
  595. boolean IS_STWALL(typ)
  596. unsigned typ;
  597. {
  598.     return(typ <= TRWALL);            /* STONE <= (typ) <= TRWALL */
  599. }
  600.  
  601. boolean IS_ROCK(typ)
  602. unsigned typ;
  603. {
  604.     return(typ < POOL);            /* absolutely nonaccessible */
  605. }
  606.  
  607. boolean IS_DOOR(typ)
  608. unsigned typ;
  609. {
  610.     return(typ == DOOR);
  611. }
  612.  
  613. boolean ACCESSIBLE(typ)
  614. unsigned typ;
  615. {
  616.     return(typ >= DOOR);            /* good position */
  617. }
  618.  
  619. boolean IS_ROOM(typ)
  620. unsigned typ;
  621. {
  622.     return(typ >= ROOM);            /* ROOM, STAIRS, furniture.. */
  623. }
  624.  
  625. boolean ZAP_POS(typ)
  626. unsigned typ;
  627. {
  628.     return(typ >= POOL);
  629. }
  630.  
  631. boolean SPACE_POS(typ)
  632. unsigned typ;
  633. {
  634.     return(typ > DOOR);
  635. }
  636.  
  637. boolean IS_POOL(typ)
  638. unsigned typ;
  639. {
  640.     return(typ >= POOL && typ <= DRAWBRIDGE_UP);
  641. }
  642.  
  643. boolean IS_THRONE(typ)
  644. unsigned typ;
  645. {
  646.     return(typ == THRONE);
  647. }
  648.  
  649. boolean IS_FOUNTAIN(typ)
  650. unsigned typ;
  651. {
  652.     return(typ == FOUNTAIN);
  653. }
  654.  
  655. boolean IS_SINK(typ)
  656. unsigned typ;
  657. {
  658.     return(typ == SINK);
  659. }
  660.  
  661. boolean IS_ALTAR(typ)
  662. unsigned typ;
  663. {
  664.     return(typ == ALTAR);
  665. }
  666.  
  667. boolean IS_DRAWBRIDGE(typ)
  668. unsigned typ;
  669. {
  670.     return(typ == DRAWBRIDGE_UP || typ == DRAWBRIDGE_DOWN);
  671. }
  672.  
  673. boolean IS_FURNITURE(typ)
  674. unsigned typ;
  675. {
  676.     return(typ >= STAIRS && typ <= ALTAR);
  677. }
  678. #endif /* STUPID_CPP */
  679.  
  680. #endif /* OVLB */
  681.